using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
using IDEInterfaceLibrary;

namespace NewRootProject
{
    public class NewRootProjectWizard : IDTWizard
    {
        #region IDTWizard Members

        public void Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref wizardResult retval)
        {
            ProjecConfigDialog dlg = new ProjecConfigDialog();
            DialogResult dlg_result = dlg.ShowDialog();
            if (dlg_result == DialogResult.OK)
            {
                ROOTBuildConfig rc = new ROOTBuildConfig();
                rc.Directory = dlg.ROOTFolder;
                rc.ProjectName = (string) ContextParams[1];

                EnvDTE.DTE myDTE = (EnvDTE.DTE)Application;
                myDTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Close(vsSaveChanges.vsSaveChangesYes);
                UIHierarchy toplevel = (UIHierarchy)myDTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Object;

                ProgressDialog pdlg = new ProgressDialog();
                pdlg.Show();

                CreateROOTProject.CreateProject(rc, new MSVCSolution(myDTE.Solution), toplevel);
                myDTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Visible = true;
                pdlg.Close();

                retval = wizardResult.wizardResultSuccess;
            }
            else
            {
                retval = wizardResult.wizardResultCancel;
            }
        }

        #endregion
    }
}
